package com.kgc.itrip.component;

import com.cloopen.rest.sdk.BodyType;
import com.cloopen.rest.sdk.CCPRestSmsSDK;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Set;
@Component
@ConfigurationProperties(prefix = "sms")
@Data
public class SmsTools {
    private String serverIp;
    private String serverPort;
    private String accountSId;
    private String accountToken;
    private String appId;

    public boolean sendPhoneSMS(String sendTo, String templateId, String[] datas) {
        //生产环境请求地址：app.cloopen.com
        //String serverIp = "app.cloopen.com";
        //请求端口
        //String serverPort = "8883";
        //主账号,登陆云通讯网站后,可在控制台首页看到开发者主账号ACCOUNT SID和主账号令牌AUTH TOKEN
        //String accountSId = "8aaf0708780055cd01781c8e4ac90acf";
        //String accountToken = "83e7ce3127bb41bbb2d95ad217cba750";
        //请使用管理控制台中已创建应用的APPID
        //String appId = "8aaf0708780055cd01781c8e4b940ad5";
        CCPRestSmsSDK sdk = new CCPRestSmsSDK();
        sdk.init(serverIp, serverPort);
        sdk.setAccount(accountSId, accountToken);
        sdk.setAppId(appId);
        sdk.setBodyType(BodyType.Type_JSON);
        String to = "18728602037";
        //String subAppend = "1234";  //可选 扩展码，四位数字 0~9999
        //String reqId = "fadfafas";  //可选 第三方自定义消息id，最大支持32位英文数字，同账号下同一自然天内不允许重复
        HashMap<String, Object> result = sdk.sendTemplateSMS(sendTo, templateId, datas);
        //HashMap<String, Object> result = sdk.sendTemplateSMS(to, templateId, datas, subAppend, reqId);
        if ("000000".equals(result.get("statusCode"))) {
            return true;
        } else {
            return false;
        }
    }
}
